package fons.navigator.views.piemap;

import java.awt.Color;
import java.awt.Font;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;

import edu.umd.cs.piccolo.PNode;
import edu.umd.cs.piccolo.event.PBasicInputEventHandler;
import edu.umd.cs.piccolo.event.PInputEvent;
import edu.umd.cs.piccolox.util.PFixedWidthStroke;
import fons.navigator.util.piccolo.PLabel;

public class CircleDrawingStrategy extends DrawingStrategy {
   	private static final long serialVersionUID = 1L;
   	private static final Font labelFont = new Font("Arial", Font.PLAIN, 12);
   	private static final Stroke STROKE = new PFixedWidthStroke(1);
   	private static final Color STROKE_PAINT = new Color(0, 0, 0, 200);
	private static final Color NODE_PAINT = new Color(0, 0, 0, 90);
	private static final Stroke HIGHLIGHTED_STROKE = new PFixedWidthStroke(2);
	private static final Color HIGHLIGHTED_STROKE_PAINT = new Color(0, 0, 0, 200);
	private static final Color HIGHLIGHTED_NODE_PAINT = new Color(200, 200, 0, 200);
	
   	private final PLabel label;
   	
	public CircleDrawingStrategy(Target target, PNode positionHint) {
        super(target, positionHint);
        final double size = 20.0f;
        this.append(new Ellipse2D.Double(-size/2,-size/2, size, size), true);
        
        this.label = new PLabel(target.getTargetDimension().getName());
        this.label.setHighlightOnMouseOver(false);
        this.label.setFont(labelFont);
        this.addChild(label);
        this.label.setVisible(false);
        
        setStroke(STROKE);
		setStrokePaint(STROKE_PAINT);
		setPaint(NODE_PAINT);
        
        this.addInputEventListener(new PBasicInputEventHandler() {
        	@Override
        	public void mouseEntered(PInputEvent event) {
        		label.setVisible(true);
        		setStroke(HIGHLIGHTED_STROKE);
        		setStrokePaint(HIGHLIGHTED_STROKE_PAINT);
        		setPaint(HIGHLIGHTED_NODE_PAINT);
        	}
        	
        	@Override
        	public void mouseExited(PInputEvent event) {
        		label.setVisible(false);
        		setStroke(STROKE);
        		setStrokePaint(STROKE_PAINT);
        		setPaint(NODE_PAINT);
        	}
        });
    }
 
    @Override
    public void showLegend() {
    }

    @Override
    public void hideLegend() {
    }

	@Override
	public void zOrder() {
		getTarget().moveToBack();
	}
}
